package com.xyht.sca_s.student_manage_system.modules.assetFixedChange.controller;


import com.xyht.sca_s.student_manage_system.auth.util.JwtTokenUtil;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.assetFixedChange.entity.req.SmsAssetFixedChangeApplyAllowReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedChange.entity.req.SmsAssetFixedChangeApplyReq;
import com.xyht.sca_s.student_manage_system.modules.assetFixedChange.service.SmsAssetFixedChangeApplyService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 资产变动申请 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-09-25
 */
@RestController
@RequestMapping("/assetFixedChange")
@SecretBody
public class SmsAssetFixedChangeApplyController {
    @Resource
    private SmsAssetFixedChangeApplyService smsAssetFixedChangeApplyService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiModelProperty(value = "提交资产变动申请")
    @PostMapping("/add")
    public ResponseResult addFixedChangeApply(@RequestBody @Validated SmsAssetFixedChangeApplyReq req, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedChangeApplyService.addFixedChangeApply(req, user_id);
    }

    @ApiModelProperty(value = "撤销资产变动申请")
    @PostMapping("/cancel")
    public ResponseResult cancelFixedChangeApply(@RequestBody SmsAssetFixedChangeApplyReq cancelReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedChangeApplyService.cancelFixedChangeApply(cancelReq, user_id);
    }

    @ApiModelProperty(value = "审批")
    @PostMapping("/allow")
    public ResponseResult allowAssetFixedChangeApply(@RequestBody SmsAssetFixedChangeApplyAllowReq allowReq, HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedChangeApplyService.allowAssetFixedChangeApply(allowReq, user_id);
    }

    @ApiModelProperty(value = "审批列表")
    @GetMapping("/list")
    public ResponseResult getAssetFixedChangeApplyList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                          @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                          @RequestParam(value = "apply_type") Integer apply_type,
                                                          HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedChangeApplyService.getAssetFixedChangeApplyList(user_id, apply_type, pageNum, pageSize);
    }

    @ApiModelProperty(value = "审批详情")
    @GetMapping("/detail")
    public ResponseResult getAssetFixedChangeApplyDetail(@RequestParam(value = "apply_id") String apply_id,
                                                            HttpServletRequest request) {
        String user_id = jwtTokenUtil.getUserIdByRequest(request);
        return smsAssetFixedChangeApplyService.getAssetFixedChangeApplyDetail(apply_id, user_id);
    }

    @ApiModelProperty(value = "获取所有审批列表")
    @GetMapping("/allList")
    public ResponseResult getAssetFixedChangeApplyAllList(@RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                             @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                             @RequestParam(value = "allowStatus", required = false) Integer allowStatus,
                                                             @RequestParam(value = "applyUserName", required = false) String applyUserName) {
        return smsAssetFixedChangeApplyService.getAssetFixedChangeApplyAllList(allowStatus,applyUserName ,pageNum, pageSize);
    }
}

